package com.sunny.shop.util;

import javax.persistence.AttributeConverter;
import java.util.HashMap;
import java.util.Map;

public class StringAndArray implements AttributeConverter<Map<Integer, String>, String> {
    @Override
    public String convertToDatabaseColumn(Map<Integer, String> integerStringMap) {
        return null;
    }

    @Override
    public Map<Integer, String> convertToEntityAttribute(String s) {
        HashMap<Integer,String> storyTag = new HashMap<>();
        storyTag.put(1,"励志成长");
        storyTag.put(2,"友情");
        storyTag.put(3,"冒险");
        storyTag.put(4,"启蒙");
        storyTag.put(5,"家庭教育");
        storyTag.put(6,"情绪管理");
        storyTag.put(7,"行为养成");
        storyTag.put(8,"智力提升");
        HashMap<Integer, String> tagList = new HashMap<>();
        if(s != null){
            String[] tagArr = s.split(",");
            for (int i = 0; i < tagArr.length; i++) {
                Integer key = Integer.valueOf(tagArr[i]);
                tagList.put(i,storyTag.get(key));
            }
        }
        return tagList;
    }
}
